lib/sysroot: Add OSTREE_EX_STAGE_DEPLOYMENTS environment variable
authorColin Walters <walters@verbum.org>
Thu, 3 May 2018 21:29:06 +0000 (17:29 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Fri, 11 May 2018 12:39:17 +0000 (12:39 +0000)
I feel like I'm drowning in a pile of experimental-but-almost-stable
features...

Anyways, since we made the feature opt-in in rpm-ostree in
https://github.com/projectatomic/rpm-ostree/pull/1352
let's mirror that a bit here with an environment variable so people
can play with it more easily.

The tests needed some tweaks; specifically we need to reload the
status fact after making changes.  I'm still a bit uncertain
about the Ansible-as-tests.

But we add an upgrade test that uses the new environment variable.

Closes: #1583
Approved by: jlebon

src/libostree/ostree-sysroot-upgrader.c
tests/admin-test.sh
tests/installed/destructive-ansible.yml
tests/installed/destructive/staged-deploy.yml
tests/installed/tasks/install-git.yml
tests/installed/tasks/query-host.yml

index a87548a346f1ac2b2209eca38762e3caaf161c64..8fb231a3f70e699e22ecff9be27e4cfbce96acb2 100644 (file)
@@ -644,21 +644,37 @@ ostree_sysroot_upgrader_deploy (OstreeSysrootUpgrader  *self,
                                 GError                **error)
 {
   g_autoptr(OstreeDeployment) new_deployment = NULL;
-  if (!ostree_sysroot_deploy_tree (self->sysroot, self->osname,
-                                   self->new_revision,
-                                   self->origin,
-                                   self->merge_deployment,
-                                   NULL,
-                                   &new_deployment,
-                                   cancellable, error))
-    return FALSE;
 
-  if (!ostree_sysroot_simple_write_deployment (self->sysroot, self->osname,
-                                               new_deployment,
-                                               self->merge_deployment,
-                                               0,
-                                               cancellable, error))
-    return FALSE;
+  /* Experimental flag to enable staging */
+  if (getenv ("OSTREE_EX_STAGE_DEPLOYMENTS"))
+    {
+      if (!ostree_sysroot_stage_tree (self->sysroot, self->osname,
+                                      self->new_revision,
+                                      self->origin,
+                                      self->merge_deployment,
+                                      NULL,
+                                      &new_deployment,
+                                      cancellable, error))
+        return FALSE;
+    }
+  else
+    {
+      if (!ostree_sysroot_deploy_tree (self->sysroot, self->osname,
+                                       self->new_revision,
+                                       self->origin,
+                                       self->merge_deployment,
+                                       NULL,
+                                       &new_deployment,
+                                       cancellable, error))
+        return FALSE;
+
+      if (!ostree_sysroot_simple_write_deployment (self->sysroot, self->osname,
+                                                   new_deployment,
+                                                   self->merge_deployment,
+                                                   0,
+                                                   cancellable, error))
+        return FALSE;
+    }
 
   return TRUE;
 }
index dd87cd110ca9e296ab83a3c1905f795604c7ac56..7384d8f3ddeab4ce84e6d39b7137e89ed4070f7d 100644 (file)
@@ -21,7 +21,7 @@
 
 set -euo pipefail
 
-echo "1..$((24 + ${extra_admin_tests:-0}))"
+echo "1..$((25 + ${extra_admin_tests:-0}))"
 
 function validate_bootloader() {
     cd ${test_tmpdir};
@@ -215,6 +215,11 @@ validate_bootloader
 echo "ok upgrade bare"
 
 os_repository_new_commit
+if env OSTREE_EX_STAGE_DEPLOYMENTS=1 ${CMD_PREFIX} ostree admin upgrade --os=testos 2>err.txt; then
+    fatal "staged when not booted"
+fi
+echo "ok upgrade failed when staged"
+
 ${CMD_PREFIX} ostree --repo=sysroot/ostree/repo remote add --set=gpg-verify=false testos file://$(pwd)/testos-repo testos/buildmaster/x86_64-runtime
 ${CMD_PREFIX} ostree admin upgrade --os=testos
 origrev=${rev}
index a0e69aa16e745c80eebf9f0581aacc7b45533fa7..c72f6b82c3c03bedbb0bc4028c0c97acdb978458 100644 (file)
@@ -9,10 +9,7 @@
     tests: "."
   tasks:
     - import_tasks: tasks/disable-all-rpmmd-repos.yml
-    - import_tasks: tasks/query-host.yml
-    - set_fact:
-        rpmostree_initial_deployment: "{{ rpmostree_status[\"deployments\"][0] }}"
     - import_tasks: tasks/install-git.yml
       when: use_git_build
-
+    - import_tasks: tasks/query-host.yml
     - import_tasks: destructive/staged-deploy.yml
index 723dbf55b1521545f5aca2ee3943c91216710f81..f34550a2a2bea2d390d903290782f868e9e5e2af 100644 (file)
 - name: Check that deploy-staged service worked
   shell: |
     set -xeuo pipefail
+    rpm-ostree status
     # Assert that the previous boot had a journal entry for it
     journalctl -b "-1" -u ostree-finalize-staged.service | grep -q -e 'Transaction complete'
     # And there should not be a staged deployment
     test '!' -f /run/ostree/staged-deployment
-- name: Rollback
-  shell: rpm-ostree rollback
-- include_tasks: ../tasks/reboot.yml
-- shell: |
+
+- name: Upgrade with staging
+  shell: |
     set -xeuo pipefail
+    test '!' -f /run/ostree/staged-deployment
+    ostree admin deploy --stage staged-deploy
+    test -f /run/ostree/staged-deployment
+    origcommit=$(ostree rev-parse staged-deploy)
+    cd /ostree/repo/tmp
+    ostree checkout -H "${origcommit}" t
+    ostree commit --no-bindings --parent="${origcommit}" -b staged-deploy -I --consume t
+    newcommit=$(ostree rev-parse staged-deploy)
+    env OSTREE_EX_STAGE_DEPLOYMENTS=1 ostree admin upgrade >out.txt
+    test -f /run/ostree/staged-deployment
+    # Debating bouncing back out to Ansible for this
+    firstdeploycommit=$(rpm-ostree status |grep 'Commit:' |head -1|sed -e 's,^ *Commit: *,,')
+    test "${firstdeploycommit}" = "${newcommit}"
+    # Cleanup
     rpm-ostree cleanup -rp
+- import_tasks: ../tasks/query-host.yml
 
 # Ensure we can unstage
 - name: Write staged-deploy commit, then unstage
@@ -50,8 +65,6 @@
     ostree admin status > status.txt
     grep -vqFe '(staged)' status.txt
     test '!' -f /run/ostree/staged-deployment
-  environment:
-    commit: "{{ rpmostree_status['deployments'][0]['checksum'] }}"
 
 - name: Staged should be overwritten by non-staged
   shell: |
index 33fe385e7e8e7946d17c3cf717b6f53bb61e56a7..8216afeb1572343392b864088551ec7684e4c2eb 100644 (file)
@@ -8,7 +8,8 @@
   synchronize: src=build/x86_64/ dest=/root/x86_64/ archive=yes
 - name: Install RPMs
   shell: rpm-ostree override replace /root/x86_64/*.rpm
-- include_tasks: ../tasks/reboot.yml
+- import_tasks: ../tasks/reboot.yml
+- import_tasks: ../tasks/query-host.yml
 - command: ostree --version
   register: ostree_new_version
 - set_fact:
index 2a67dbdf9076bd59db6ce450aee627862863346a..d572ae64b6a00a4e54a4174d61cd1f5eed804e8f 100644 (file)
@@ -1,4 +1,5 @@
-- command: rpm-ostree status --json
+- name: Load status json
+  command: rpm-ostree status --json
   changed_when: False
   register: rpmostree_status_json
 - set_fact: